<template>
  <div class="home">
    <div class="form">
      <div>name: <input type="text" v-model="userInfo.name" /></div>
      <div>
        &nbsp;&nbsp;age: <input type="text" v-model="userInfo.age" /><br />
      </div>
      <input type="submit" value="提交" @click="submit" class="submit" />
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
import qs from "qs";

export default {
  name: "Home",
  data: () => {
    return {
      userInfo: {
        name: "liuweihua",
        age: 29,
      },
    };
  },
  methods: {
    submit() {
      fetch("/api/login", {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
        },
        body: qs.stringify(this.userInfo),
      })
        .then((value) => value.json())
        .then((res) => {
          console.log(res);
        });
    },
  },
  created() {
    window.localStorage.setItem('main', 'home')
  }
};
</script>
<style lang="scss" scoped>
.form {
  width: 400px;
  margin: 50px auto;
  border: 1px solid #000;
  padding: 30px;
  
  div {
    margin-bottom: 15px;
    input {
      width: 300px;
      height: 30px;
    }
  }
  .submit {
    width: 300px;
    height: 40px;
  }
}
</style>
